<template>
  <div class="complaint">
    <div class="taber">
      <span>投诉建议列表</span>
    </div>
    <div class="navquire">
      <el-form
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
        ref="formInline"
      >
        <el-form-item label="投诉标题" prop="key">
          <el-input v-model="formInline.key" placeholder="投诉标题"></el-input>
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="formInline.address" placeholder="地址 "></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="tel">
          <el-input v-model="formInline.tel" placeholder="电话"></el-input>
        </el-form-item>
        <el-form-item label="按时间查询-" prop="begindate">
          <el-date-picker
            v-model="formInline"
            type="datetimerange"
            :picker-options="formInline.begindate"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            align="right"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="投诉状态" prop="state">
          <el-select v-model="formInline.state" placeholder="请选择">
            <el-option
              v-for="item in list"
              :label="item.name"
              :value="item.id"
              :key="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="投诉类型" prop="type">
          <el-select v-model="formInline.type" placeholder="请选择">
            <el-option
              v-for="item in lists"
              :label="item.name"
              :value="item.id"
              :key="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="居民" prop="userid">
          <el-input
            v-model="formInline.userid"
            placeholder="请输入关键字"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onlists">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div classs="del">
      <el-button @click="addShow(true)">添加</el-button>
      <el-button type="danger" @click="onRear">批量删除</el-button>
    </div>
    <!-- <el-table
      class="list"
      @selection-change="handleSelectionChange"
      :data="tableData"
      v-loading="loading"
      border
    >
      <el-table-column type="selection" width="50"> </el-table-column>
      <el-table-column fixed prop="id" label="id" width="180">
      </el-table-column>
      <el-table-column prop="typename" label="问题类型" width="180">
      </el-table-column>
      <el-table-column prop="address" label="问题地址" width="240">
      </el-table-column>
      <el-table-column prop="content" label="问题描述" width="180">
      </el-table-column>
      <el-table-column prop="statename" label="处理状态" width="180">
      </el-table-column>
      <el-table-column prop="username" label="业主名称" width="180">
      </el-table-column>
      <el-table-column prop="tel" label="业主电话" width="180">
      </el-table-column>
      <el-table-column prop="addtime" label="维修日期" width="180">
      </el-table-column>
      <el-table-column label="操作 " width="180" prop="id">
        <template slot-scope="scope">
          <el-row>
            <el-button type="success" size="mini" @click="addShow(true,scope.row)">修改</el-button>
            <el-button
              type="danger"
              size="mini"
              @click="deletelist_id(scope.row.id)"
              >删除
            </el-button>
          </el-row>
        </template>
      </el-table-column>
    </el-table> -->
    <Table
      :loading="loading"
      :tableData="tableData"
      :tableHead="tableHead"
      :handleSelectionChange="handleSelectionChange"
      @stateChange="stateChange"
      @updateNotice="addShow"
      @deleteNotice="deleteNotice"
      @textView="textView"
    />
<!--     <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="formInline.page"
      :page-sizes="[5, 10, 20, 50]"
      :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination> -->
    <Questionsadd
      :show="showloding"
      :titleFlag="titleFlag"
      :updateData="updateData"
      @close="addShow"
    />
    <Pageination
       :pageSize = 'formInline.psize'
       :total='total'
       @changpage="onlists"
    />
  </div>
</template>

<script>
import axios from "axios";
import http from '../api/goods'
import Questionsadd from "./../components/common/Questionsadd.vue";
import Table from "./../components/common/Table.vue";
import Pageination from "./../components/common/page1.vue";
// Questionsadd
export default {
  components: {
    Questionsadd,
    Table,
    Pageination
  },
  data() {
    return {
      showloding: false,
      updateData: {},
      titleFlag: false,
      
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      tableHead: [
        {
          label: "ID",
          prop: "id",
        },
        {
          label: "问题类型 ",
          prop: "typename",
          type: "isclick",
        },
        {
          label: "问题地址",
          prop: "address",
          type: "isclick",
        },
        {
          label: "问题描述",
          prop: "content",
          type: "isclick",
        },
        {
          label: "处理状态",
          prop: "statename",
          type: "isclick",
        },
        {
          label: "业主名称",
          prop: "username",
          type: "isclick",
        },
        {
          label: "业主电话",
          prop: "tel",
          type: "isclick",
        },
        {
          label: "维修日期",
          prop: "addtime",
          type: "isclick",
        },
        {
          label: "操作",
          type: "button",
          button: {
            update: true,
            delete: true,
          },
        },
        // {
        //   label: "添加人",
        //   prop: "edituser",
        //   type: "isclick",
        // },
        // {
        //   label: "头像",
        //   prop: "picture",
        //   type: "img",
        //   imgclick: true,
        //   formatter: (row, prop) => {
        //     // console.log(row, prop, this.$config.baseUrl);
        //     // console.log(row, prop, this.$config.baseUrl);
        //     //模拟测试
        //     let defImg =
        //       "/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic_source%2F30%2F90%2F40%2F309040a0602c672cebc6ab3a1bbbc8cd.jpg";
        //     let baseUrl = "https://gimg2.baidu.com/image_search";
        //     return !prop ? defImg : this.$config.baseUrl + "/upload/" + prop;
        //     return baseUrl + "upload" + prop;
        //   },
        // },
        // {
        //   label: "图片",
        //   prop: "images",
        //   type: "img",
        //   imgclick: true,
        //   formatter: (row, prop) => {
        //     // console.log(row, prop, this.$config.baseUrl);
        //     let defImg =
        //       "/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic_source%2F84%2F69%2Fa9%2F8469a992634242df4291b3265f9f2a38.jpg";
        //     prop = [
        //       {
        //         url: defImg,
        //       },
        //       {
        //         url: defImg,
        //       },
        //     ];
        //     let baseUrl = "https://gimg2.baidu.com/image_search"
        //     const images = prop.map(item=>baseUrl+item.url)
        //     return {
        //       url:  images[0],
        //       images
        //     }

        //   },
        // },
      ],
      value1: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
      value2: "",
      formInline: {
        key: "",
        address: "",
        tel: "",
        userid: "",
        begindate: "",
        enddate: "",
        state: "",
        type: "",
        page: 1,
        psize: 5,
      },
      tableData: [],
      multipleSelection: [],
      list: [],
      lists: [],
      loading: true,
      currentPage4: 4,
      total: 0,
    };
  },
  mounted() {
    this.onlists();
    this.questionstate();
    this.questiontype();
  },
  methods: {
    //状态菜单
    /**
     * 显示,隐藏，操作 ->[添加/修改/关闭/取消/确定]
     * @param show Boolean 显示 隐藏
     * @param data Object 修改时的数据
     * @param flag Number 控制列表渲染的标识
     */
    async addShow(show, data, flag) {
      this.showloding = show;
      console.log(show, data, flag);
      if (show) {
        this.titleFlag = !!data;
        if (this.titleFlag) {
          const rel = this.tableData.find((item) => item.id == data.id);
          this.updateData = rel;
        }
        this.onlists();
      } else {
        flag && this.onlists();
        this.updateData = {};
      }
    },
    async questionstate() {
      const { data, errCode } = await http.questionstate({
        page: this.page,
        pageSize: this.pageSize,
      });
      if (errCode == "10000") {
        this.list = data.list;
      }
    },
    //类型菜单
    async questiontype() {
      const { data, errCode } = await http.questiontype();
      console.log(data);
      if (errCode == "10000") {
        this.lists = data.list;
      }
    },
    //列表渲染
    async onlists(params) {
      console.log(params)
      this.loading = true;
      // console.log(this.formInline)
      // co nst formInline = this.formInline/*  */

      /*  const { data: res, errCode } = await questions({formInline}) */ // console.log(formInline)
      /*  console.log(res, errCode, res.pageCounts, res.pageSize);
      if (errCode == "10000") {
        this.loading = false;
        this.tableData = res.list;
        this.page = res.pageSize;
        this.psize = res.pageCounts;
      } */
      // const  {data} = await questions()
      axios
        .get("/api/questions/list", { params:Object.assign(this.formInline,params) })
        .then((res) => {
          if (res.data.errCode == 10000) {
            console.log(res.data);
            this.tableData = res.data.data.list;
            this.loading = false;
            this.total = res.data.data.counts;
            // this.formInline.page = res.data.data.pageCounts;
            // this.formInline.psize = res.data.data.pageSize;
            // console.log(res.data.data.counts)
          }
          // console.log(this.total, this.formInline.page, this.formInline.psize);
        });
      // console.log(this.formInline.page,this.formInline.psize,this.total,)
    },
    //单条删除
    deletelist_id(ids) {
      this.loading = true;
      let id = ids;
      console.log(id);
      axios.get("/api/questions/delete", { params: { id: id } }).then((res) => {
        this.loading = false;
        this.onlists();
      });
    },
    //批量删除
    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log(val);
    },
    onRear() {
      if (this.multipleSelection == 0) {
        this.$message({
          showClose: true,
          message: "请勾选需要删除的数据",
          type: "error",
        });
      }
      let arr = [];
      this.multipleSelection.forEach((item) => {
        console.log(item)
        arr.push(item.id);
      });
      // console.log(arr)
      questiontypeDelAll({ ids: arr }).then((res) => {
        if (res.errCode == 10000) {
          this.onlists();
        }
      });
    },
    idqwe(id) {
      console.log(id);
    },
    handleSizeChange(val) {
      this.formInline.psize = val;
      this.onlists();
    },
    handleCurrentChange(val) {
      this.formInline.page = val;
      this.onlists();
    },
    stateChange(data) {
      console.log("stateChange", data);
    },
    updateNotice(data) {
      console.log("updateNotice", data);
    },
    async deleteNotice(data) {
      const { errCode } = await http.questiontypeDel({ id: data.id });
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.onlists();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    textView(data) {
      console.log("textView", data);
    },
    async getNoticeList() {
      const { data } = await http.getAdministratorrole();
      this.tableData = data.list;
      console.log(data);
    },
  },
};
</script>

<style lang="less">
.el-table--enable-row-transition .el-table__body td.el-table__cell {
  text-align: center !important;
}
.complaint {
  padding: 20px;
}

.taber {
  color: rgb(66, 127, 244);
  height: 50px;
  border-bottom: 1px solid #cccc;
}
.navquire {
  margin-top: 30px;
}
.list {
  margin-top: 20px;
}
.el-table {
  width: 100% !important;
}

.el-table th.el-table__cell > .cell {
  text-align: center !important;
}
.el-table td.el-table__cell div {
  text-align: center !important;
}
</style>